// bind/pages/staff/staff.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    account:false,
    password:false
  },
  onLoad:function(t){},
  onShow: function (t) {
    let _t = this,token = wx.getStorageSync('ACCESS_TOKEN')
    getApp().page.onLoad(_t)
    token && getApp().page.checkBinding()
  },
  //监听输入的帐号
  account:function(e){
    this.data.account=e.detail.value;
  },
  //监听输入的密码
  password:function(e){
    this.data.password=e.detail.value;
  },
  bind:function(){
    if(this.data.account && this.data.password){
      getApp().core.showLoading()
      wx.request({
        url: "https://live.sgwxmini.com/action/wxminibinduser",
        data: {
          store_id: getApp().api.siteinfo.acid,
          access_token:wx.getStorageSync('ACCESS_TOKEN'),
          account:this.data.account,
          password:this.data.password,
        },
        success: function(res) {
          getApp().core.hideLoading()
          if (0 == res.data.code) {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration:2000,
              success: function() {
                setTimeout(function() {
                  getApp().core.redirectTo({url: "/pages/index/index"})
                }, 2000)
              }
            })
          }else{
            let msg = res.data.msg=''?'绑定失败':res.data.msg
            wx.showToast({
              title: msg,
              icon: 'none'
            })
          }
        }
      })
    }else{
      wx.showToast({title: '账号密码不能为空',icon: 'none'})
    }
  }
})